package com.xgl.controller;


import com.xgl.pojo.Department;
import com.xgl.pojo.RespBean;
import com.xgl.service.IDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 最最帅气的熊国林
 * @since 2021-05-09
 */
@RestController
@RequestMapping("/system/basic/depart")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation(value = "获取全部学院信息")
    @GetMapping("/")
    private List<Department> getAllDepartment(){
        return departmentService.list();
    }

    @ApiOperation(value = "添加学院信息")
    @PostMapping("/")
    private RespBean addDepartment(@RequestBody Department department){
        department.setCreateDate(LocalDateTime.now());
        if (departmentService.save(department)){
            return RespBean.success("添加学院成功");
        }
        return RespBean.error("添加学院失败");
    }

    @ApiOperation(value = "修改学院信息")
    @PutMapping("/")
    private RespBean updateDepartment(@RequestBody Department department){
        if (departmentService.updateById(department)){
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }

    @ApiOperation(value = "删除学院信息")
    @DeleteMapping("/{id}")
    private RespBean deleteDepartment(@PathVariable Integer id){
        if (departmentService.removeById(id)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @ApiOperation(value = "批量删除职位信息")
    @DeleteMapping("/")
    public RespBean deleteDepartmentByIds(Integer[] ids){
        if (departmentService.removeByIds(Arrays.asList(ids))){
            return RespBean.success("批量删除成功");
        }
        return RespBean.error("批量删除失败");
    }

}
